package com.blrs.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.blrs.common.annotation.Log;
import com.blrs.common.core.controller.BaseController;
import com.blrs.common.core.domain.AjaxResult;
import com.blrs.common.enums.BusinessType;
import com.blrs.domain.ProjectProductInfo;
import com.blrs.service.project.productInfo.IProjectProductInfoService;
import com.blrs.common.utils.poi.ExcelUtil;
import com.blrs.common.core.page.TableDataInfo;

/**
 * 项目产品Controller
 * 
 * @author wangchao
 * @date 2023-12-04
 */
@RestController
@RequestMapping("/project/projectProductInfo")
public class ProjectProductInfoController extends BaseController
{
    @Autowired
    private IProjectProductInfoService projectProductInfoService;

    /**
     * 查询项目产品列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ProjectProductInfo projectProductInfo)
    {
        startPage();
        List<ProjectProductInfo> list = projectProductInfoService.selectProjectProductInfoList(projectProductInfo);
        return getDataTable(list);
    }

    /**
     * 导出项目产品列表
     */
    @Log(title = "项目产品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProjectProductInfo projectProductInfo)
    {
        List<ProjectProductInfo> list = projectProductInfoService.selectProjectProductInfoList(projectProductInfo);
        ExcelUtil<ProjectProductInfo> util = new ExcelUtil<ProjectProductInfo>(ProjectProductInfo.class);
        util.exportExcel(response, list, "项目产品数据");
    }

    /**
     * 获取项目产品详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(projectProductInfoService.selectProjectProductInfoById(id));
    }

    /**
     * 新增项目产品
     */
    @Log(title = "项目产品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProjectProductInfo projectProductInfo)
    {
        return toAjax(projectProductInfoService.insertProjectProductInfo(projectProductInfo));
    }

    /**
     * 修改项目产品
     */
    @Log(title = "项目产品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProjectProductInfo projectProductInfo)
    {
        return toAjax(projectProductInfoService.updateProjectProductInfo(projectProductInfo));
    }

    /**
     * 删除项目产品
     */
    @Log(title = "项目产品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(projectProductInfoService.deleteProjectProductInfoByIds(ids));
    }

    @Log(title = "项目产品", businessType = BusinessType.DELETE)
    @DeleteMapping("/productInfo/{projectId}")
    public AjaxResult removeByProjectId(@PathVariable String projectId)
    {
        return toAjax(projectProductInfoService.deleteProjectProductInfoByProjectId(projectId));
    }
}
